package com.ruoyi.pms.controller;

import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.pms.domain.PmsProject;
import com.ruoyi.pms.service.IPmsProjectService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 项目信息Controller
 *
 * @author huikai
 * @date 2025-03-18
 */
@RestController
@RequestMapping("/pms/project")
public class PmsProjectController extends BaseController
{
    @Autowired
    private IPmsProjectService pmsProjectService;

    /**
     * 查询项目信息列表
     */
    @PreAuthorize("@ss.hasPermi('pms:project:list')")
    @GetMapping("/list")
    public TableDataInfo list(PmsProject pmsProject)
    {
        startPage();
        List<PmsProject> list = pmsProjectService.selectPmsProjectList(pmsProject);
        return getDataTable(list);
    }

    /**
     * 导出项目信息列表
     */
    @PreAuthorize("@ss.hasPermi('pms:project:export')")
    @Log(title = "项目信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PmsProject pmsProject)
    {
        List<PmsProject> list = pmsProjectService.selectPmsProjectList(pmsProject);
        ExcelUtil<PmsProject> util = new ExcelUtil<PmsProject>(PmsProject.class);
        util.exportExcel(response, list, "项目信息数据");
    }

    /**
     * 获取项目信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('pms:project:query')")
    @GetMapping(value = "/{projectId}")
    public AjaxResult getInfo(@PathVariable("projectId") String projectId)
    {
        return success(pmsProjectService.getInfoByProjectId(projectId));
    }

    /**
     * 新增项目信息
     */
    @PreAuthorize("@ss.hasPermi('pms:project:add')")
    @Log(title = "项目信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PmsProject pmsProject)
    {
        return toAjax(pmsProjectService.add(pmsProject));
    }

    /**
     * 修改项目信息
     */
    @PreAuthorize("@ss.hasPermi('pms:project:edit')")
    @Log(title = "项目信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PmsProject pmsProject)
    {
        return toAjax(pmsProjectService.edit(pmsProject));
    }

    /**
     * 删除项目信息
     */
    @PreAuthorize("@ss.hasPermi('pms:project:remove')")
    @Log(title = "项目信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{projectIds}")
    public AjaxResult remove(@PathVariable String[] projectIds)
    {
        return toAjax(pmsProjectService.removeByProjectIds(projectIds));
    }
}